package com.clh.seckill.controller;

import com.clh.seckill.service.UserService;
import com.clh.seckill.utils.MD5Util;
import com.clh.seckill.utils.VaildatorUtil;
import com.clh.seckill.vo.LoginVo;
import com.clh.seckill.vo.RespBean;
import com.clh.seckill.vo.RespBeanEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

@Controller
@RequestMapping("/login")
@Slf4j
public class LoginController {
    @Autowired
    UserService userService;

    @RequestMapping(value = {"/index"})
    public String toLogin(Model model,HttpServletRequest request){
        //取系统中的加密盐
        model.addAttribute("salt",  MD5Util.SALT);
        Object identity_out = request.getAttribute("identity_out");
        model.addAttribute("identity_out",identity_out);
        return "login";
    }
    @PostMapping("/doLogin")
    @ResponseBody
    public RespBean login(@RequestBody @Valid  LoginVo vo, HttpServletRequest request, HttpServletResponse response){
        log.info("{}",vo);
        return userService.doLogin(vo,request,response);
    }




}
